package top.xiangqifu.springboot2_auth.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.xiangqifu.springboot2_auth.base.BaseDataResult;
import top.xiangqifu.springboot2_auth.base.BaseResult;
import top.xiangqifu.springboot2_auth.entity.AuthInfo;
import top.xiangqifu.springboot2_auth.entity.TbAuthUser;
import top.xiangqifu.springboot2_auth.entity.TbAuthUserInfo;
import top.xiangqifu.springboot2_auth.service.AuthService;
import top.xiangqifu.springboot2_auth.vo.PwdVo;
import top.xiangqifu.springboot2_auth.vo.UserVo;

import java.util.List;


@Api(tags = "用户信息相关接口")
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthService authService;


    @ApiOperation(value ="用户登录",notes = "用户登录功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户账号",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "password",value = "用户密码",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @PostMapping("/login")
    public BaseResult login(@RequestBody TbAuthUser user){
        return authService.login(user);
    }

    @ApiOperation(value ="用户注册",notes = "用户注册功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户账号",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "password",value = "用户密码",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "nickname",value = "用户名",dataTypeClass = String.class ,required = true ),
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @PostMapping("/reg")
    public BaseResult<String> reg(@RequestBody UserVo userVo) throws Exception{
        return authService.reg(userVo);
    }

    @ApiOperation(value ="获取用户信息",notes = "获取用户信息功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @GetMapping("/queryUser")
    public BaseDataResult<UserVo> queryUser() throws Exception {
        return authService.queryUser();
    }

    @ApiOperation(value ="用户密码修改",notes = "用户密码修改功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "oldpwd",value = "旧登录密码，需要md5加密",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "password",value = "新登录密码，需要md5加密",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @PostMapping("/updatePwd")
    public BaseResult updatePwd(@RequestBody PwdVo pwdVo) throws Exception {
        return authService.updatePwd(pwdVo);
    }

    @ApiOperation(value ="用户附加信息修改",notes = "用户附加信息修改功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nickname",value = "用户姓名",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "sex",value = "性别，m：男，f：女，n：保密",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "email",value = "邮箱",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "phone",value = "手机号",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "imgurl",value = "头像的url地址",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @PostMapping("/updateUserInfo")
    public BaseResult update(@RequestBody TbAuthUserInfo userInfo) throws  Exception{
        return authService.update(userInfo);
    }


}
